home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
c
/
mgabra.zip
/
MGMMACS.ASM
< prev
next >
Wrap
Assembly Source File
|
1988-04-17
|
14KB
|
527 lines
;------------------------------------------------
; WHMACS - Assembly Language Macros
;------------------------------------------------
;----------------------------------------------------------
; SAVREGS - Save 8086 Registers To Tcb (task control block)
;----------------------------------------------------------
SAVREGS MACRO TASK
mov [TASK], 0 ;0 means process put to sleep
mov [TASK+2], ax
mov [TASK+4], bx
mov [TASK+6], cx
mov [TASK+8], dx
mov [TASK+10], bp
mov [TASK+12], di
mov [TASK+14], si
mov [TASK+16], es
mov [TASK+18], ds
pop [TASK+24] ;ip
pop [TASK+26] ;cs
pop [TASK+28] ;flags
mov [TASK+20], ss
mov [TASK+22], sp
ENDM
;----------------------------------------------------
; SAVCUR - Save Cursor Position To Tcb. We use direct
; hardware because some program bypass the bios and
; give an innaccurate cursor position.
;----------------------------------------------------
SAVCUR MACRO TASK
; mov dx, add6845 ;find 6845 controller
; mov al, 14 ;register number
; out dx, al ;do it
; inc dx ;set for next register
; in al, dx
; mov ah, al
; dec dx ;reset dx
; mov al, 15 ;port number
; out dx, al
; inc dx
; in al, dx
; and ax, 07ffh
; mov bl, 80
; div bl
; xchg ah, al
; mov [TASK+30], ax ;save cursor location
mov bx, 0
push bx
pop es ;set segment
mov bx, 0462h ;page number in low ram
mov bh, byte ptr es:[bx] ;get it
mov ah, 3
int 10h
mov [TASK+30], dx ;cursor position
mov [TASK+52], cx ;cursor size
ENDM
;------------------------------------------------
; RESCUR - Restore Cursor Address From Tcb
;------------------------------------------------
RESCUR MACRO TASK
LOCAL LB1, LB2
mov ax, cs:scrswp ;get screen swap mode
and ax, 1 ;is cursor swapping enabled?
jnz LB2 ;yes then do it
mov ax, cs:scrswp ;check again
and ax, 8 ;cursor swap on key switch?
jz LB1 ;if not then exit
cmp cs:keyswap, 1 ;was it done on a keyswap?
jne LB1 ;no then exit
LB2:
mov dx, [TASK+30] ;cursor row and column to dx
mov bh, byte ptr [TASK+51] ;page number
mov ah, 2 ;set cursor address function number
int 10h ;call bios
mov cx, [TASK+52] ;cursror size
mov ah, 1
int 10h
LB1:
ENDM
;------------------------------------------------
; SAVDTA - SAVE DTA ADDRESS TO TCB
;------------------------------------------------
SAVDTA MACRO TASK
mov ah, 2fh ;get dta address function number
int 21h ;call dos
mov [TASK+32], es ;save dta address segment
mov [TASK+34], bx ;save dta offset
ENDM
;------------------------------------------------
; SAV24H - Save Critical Error Address To Tcb
;------------------------------------------------
SAV24h MACRO TASK
SAVINT 24h, [TASK+36], [TASK+38]
ENDM
;------------------------------------------------
; SAV23H - Save Control Break Handler
;------------------------------------------------
SAV23h MACRO TASK
SAVINT 23h, [TASK+46], [TASK+48]
ENDM
;------------------------------------------------
; SAVPRC - Save Entire Process
;------------------------------------------------
SAVPRC MACRO TASK
SAVREGS TASK
SAVDTA TASK
SAV24H TASK
SAV23H TASK
SAVCUR TASK
SAVSCR TASK
ENDM
;------------------------------------------------
; SAVPAG - Save current video page to TCB
;------------------------------------------------
SAVPAG MACRO TASK
mov bx, 0
push bx
pop es ;set segment
mov bx, 0462h ;page number in low ram
mov al, byte ptr es:[bx] ;get it
mov ah, 0
mov [TASK+50], ax ;save it into TCB
mov cs:videop, ax ;move it to our global variable
call VIDSEG ;calculate effective video base
ENDM
;------------------------------------------------
; SETPAG - set video page
;------------------------------------------------
SETPAG MACRO PG
mov ax, PG ;get value page
mov ah, 5 ;set video page function number
int 10h ;set it
ENDM
;------------------------------------------------
; RESPAG - Restore video page
;------------------------------------------------
RESPAG MACRO TASK
mov ax, [TASK+50] ;get value of this processes page
mov cs:videop, ax ;save it into our variable
mov ah, 5 ;set video page function number
int 10h ;set it
call VIDSEG ;calculate video base
ENDM
;------------------------------------------------
; SAVMOD - Save Video Mode To Tcb
;------------------------------------------------
SAVMOD MACRO TASK
mov bx, 0
push bx
pop es ;set segment 0
mov bx, 0449h ;set offset
mov al, es:[bx] ;get video mode
mov ah, 0 ;clear ah
mov [TASK+40], ax ;save it
mov cs:videom, ax ;place in global mode variable
ENDM
;------------------------------------------------
; RESMOD - Restore Video Mode
;------------------------------------------------
RESMOD MACRO TASK
LOCAL resmod1
mov ax, [tsrprg+40] ;compare our video modes
cmp ax, [dosprg+40] ;if not different don't switch
je resmod1 ;because mode swith is unaesthetic
mov ax, [TASK+40] ;set mode number from TCB
mov cs:videom, ax ;place in global mode variable
mov ah, 0 ;set video mode function number
int 10h ;call bios
resmod1:
ENDM
;------------------------------------------------
; LODTCK Load tasks tick allocation
;------------------------------------------------
LODTCK MACRO TASK
push [TASK+44] ;get it's ticks
pop cs:period ;load them into master timer
ENDM
;------------------------------------------------
; SAVSCR - SAVE SCREEN CONTENTS TO BUFFER
;------------------------------------------------
SAVSCR MACRO TASK
LOCAL LB1, LB2, LB3, LB4
mov ax, cs:scrswp ;get screen swap parameter
and ax, 2 ;is save screen bit set?
jnz LB4 ;yes then swap 'em
;else ...
mov ax, cs:scrswp ;check again for swap by key
and ax, 16 ;save if swap by key?
jz LB1 ;no, then exit outta here
;else ...
cmp cs:keyswap, 1 ;was swap done by key?
jne LB1 ;no, then exit.
LB4:
SAVMOD TASK ;save video mode
SAVPAG TASK ;save video page
push ds ;duck ds!
push cs ;get cs into es
pop es
mov di, [TASK+42] ;set destination offset
mov ds, cs:videos ;set source segment
mov si, 0 ;set source offset
mov cx, cs:videosz ;initialize count
cld
rep movsb ;buffer transfer
pop ds ;restore ds
LB1:
ENDM
;--------------------------------------------------
; RESSCR - Restore screen from buffer to video ram
;--------------------------------------------------
RESSCR MACRO TASK
LOCAL LB1, LB2, LB3, LB4, SNOW1, SNOW2, NOSNOW
mov ax, cs:scrswp ;get screen swap mode
and ax, 4 ;is screen restoration enabled?
jnz LB4 ;yes? do it
mov ax, cs:scrswp ;check again for swap by key
and ax, 32 ;save if swap by key?
jz LB1 ;no, then exit outta here
cmp cs:keyswap, 1 ;was swap done by key?
jne LB1 ;no, then exit.
LB4:
RESMOD TASK ;restore video mode
RESPAG TASK ;restore video page
push ds ;duck ds!
push cs ;get cs into ds
pop ds
mov si, [TASK+42] ;set source offset, assume cs seg
mov es, cs:videos ;set destination segment
mov di, 0 ;set destination offset
mov cx, cs:videosz ;initialize count
mov ax, cs:scrswp
and ax, 256 ;check for snow/no snow option
jnz NOSNOW
cld
mov dx, 03dah ;address of video controller
SNOW1:
in al, dx
and al, 1
jnz SNOW1
SNOW2:
in al, dx
and al, 1
jz SNOW2
movsb ;buffer transfer
loop SNOW1
pop ds ;restore ds
jmp LB1
NOSNOW:
cld
rep movsb
pop ds
LB1:
ENDM
;------------------------------------------------
; RES23H - Restore Control Break Handler
;------------------------------------------------
RES23h MACRO TASK
SETINT 23h, [TASK+46], [TASK+48]
ENDM
;------------------------------------------------
; RESREGS - Restore 8086